Skip to content

Conversation

@antkmsft
Copy link
Member

@antkmsft antkmsft commented Oct 9, 2025

@antkmsft antkmsft self-assigned this Oct 9, 2025
@antkmsft antkmsft marked this pull request as ready for review October 10, 2025 03:54
@Copilot Copilot AI review requested due to automatic review settings October 10, 2025 03:54
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds a new append_path() method to the Url type through an extension trait, providing a convenient way to append path segments to URLs while handling slash normalization and preserving query parameters.

  • Introduces UrlExt trait with append_path() method for intelligent URL path manipulation
  • Implements slash handling logic to avoid double slashes or missing separators
  • Adds comprehensive test coverage for various URL and path combinations

@antkmsft antkmsft requested a review from heaths October 14, 2025 01:41
Copy link
Member Author

@antkmsft antkmsft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revert "overwrite if new path starts with slash"

@github-actions
Copy link

github-actions bot commented Oct 21, 2025

API Change Check

APIView identified API level changes in this PR and created the following API reviews

typespec_client_core
azure_core

@heaths
Copy link
Member

heaths commented Oct 22, 2025

Revert "overwrite if new path starts with slash"

Then why does https://github.com/Azure/typespec-rust/pull/635 change all the paths to start with a preceding slash?

I'm not opposed to a helper in core. I suggested something like this (and query param helpers) a while back to @jhendrixMSFT. I've suggested helpers for other things more recently. And I appreciate that url::Url::join has some questionable semantics when it comes to combining paths - like making a distinction between directories and files (in a URL, there is no such thing nor any assumption that should be made) - but let's not create our own interesting behaviors. IMO, .NET's Uri has the right idea: when adding a path segment, you always delimit with a path. Full stop. Make no assumptions. If separating slash is needed, add it. If one is already there, don't add it. If there are slashes in the path you're appending, keep them. It's just an opaque string.

Copy link
Member

@heaths heaths left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better, but can be more efficient for now (see code suggestion). Before we GA, we should actually look at splitting a path in TypeSpec and building up segments more efficiently using Url::path_segments_mut(). We can then in the emitter efficiently add fixed string segments like "containers" and just append variables to be replaced with the name instead of a String::replace which is terribly inefficient to do repeatedly. The String grows more often and by smaller amounts than probably necessary if more is known up front.

In some code we'll run in tight loops like with Storage Blobs, we're going to be building up endpoints quickly in a tight loop so we'll want to optimize where we can. We can always get better, though, so this doesn't haven't to be perfect. I'd just consider my suggestion below. IMO, it's more intuitive and certainly has fewer allocations. You're will have at least 2 but likely more.

@antkmsft antkmsft requested a review from heaths October 22, 2025 18:59
@antkmsft antkmsft merged commit 5a4d5ea into Azure:main Oct 22, 2025
17 checks passed
@antkmsft antkmsft deleted the url-append-path branch October 22, 2025 22:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants